package java8;

import org.apache.poi.ss.formula.functions.T;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Stream;

public class LambdaTest11 {
    public static void main(String[] args) {
        test2();
    }

    public static void test1() {
        AtomicInteger count = new AtomicInteger(0);
        Stream.of(1, 2, 3, 4).forEach(i -> count.incrementAndGet());
        System.out.println(count.get()); // 4
    }

    /**
     * 计算小写字母最多的字符串
     */
    public static void test2() {
        System.out.println(Stream.of("Qw", "qwe", "EEE12345").max((o1, o2) ->
                (int) Stream.of(o1.split("")).filter(
                        s -> Character.isLowerCase(s.charAt(0))).count()
                        - (int) Stream.of(o2.split("")).filter(s -> Character.isLowerCase(s.charAt(0))).count())); // Optional[qwe]

    }

    public <T, S> Stream<T>  test3(Stream<S> stream, Function<S, T> fun) {
        List<T> list = new ArrayList<>();
        stream.reduce(list, (acc, ele) -> {
            list.add(fun.apply(ele));
            return acc;
        }, (ts, ts2) -> {
            list.addAll(ts);
            list.addAll(ts2);
            return list;
        });
        return list.stream();
    }
}
